import request from '@/utils/request'

// 获取所有关键词
export const getListApi = params => {
  return request({
    url: '/knowledgeAdmin/keyword/list',
    method: 'get',
    params,
  })
}


// 删除
export const deleteApi = ids => {
  return request({
    url: '/knowledgeAdmin/keyword/delete',
    method: 'delete',
    data: ids,
  })
}

// 修改
export const updateApi = data => {
  return request({
    url: '/knowledgeAdmin/keyword/update',
    method: 'put',
    data,
  })
}
// 添加
export const saveApi = data => {
  return request({
    url: '/knowledgeAdmin/keyword/save',
    method: 'post',
    data,
  })
}

// 获取关键字信息
export const getInfoApi = id => {
  return request({
    url: `/knowledgeAdmin/keyword/info/${id}`,
    method: 'get',
  })
}


/**
 * 下载关键词导入模板
 *
 * @returns
 */
export const downloadTemplateApi = ()=> {
  return request({
    url: '/knowledgeAdmin/keyword/template',
    method: 'get',
    responseType: 'arraybuffer'
  });
}

/**
 * 导出关键词
 *
 * @param queryParams
 * @returns
 */
export function exportKeywordApi(queryParams) {
  return request({
    url: '/knowledgeAdmin/keyword/_export',
    method: 'get',
    params: queryParams,
    responseType: 'arraybuffer'
  });
}

/**
 * 导入关键词
 *
 * @param file
 */
export function importKeywordApi(file) {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/knowledgeAdmin/keyword/_import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}
